package practise;

public class IsSymmetric {
    public boolean isSymmetric(TreeNode root) {
        return isSymmetricChild(root.left, root.right);
    }
    private boolean isSymmetricChild(TreeNode leftTree, TreeNode rightTree) {
//        //先判断是否为空
//        if(leftTree == null && rightTree == null) {
//            return true;
//        }
        //要么一个是空，要么全部不是空，如果有一个为空，就返回 false
        if(leftTree == null || rightTree == null) {
//            return false;
            return leftTree == null && rightTree == null;
        }
        return leftTree.val == rightTree.val &&
                isSymmetricChild(leftTree.left, rightTree.right) &&
                isSymmetricChild(leftTree.right, rightTree.left);
    }
}
